<template>
  <el-upload
    ref="uploader"
    :limit="1"
    :http-request="handleClick"
    action="/"
    :show-file-list="false"
  >
    <el-button
      v-permission="pageCode+functionCode"
      type="primary"
      icon="el-icon-upload"
      class="main-report_button"
      size="small"
    >导入</el-button>
  </el-upload>
</template>

<script>

export default {
  name: 'ListButtonImport',
  props: {
    pageCode: {
      type: String,
      required: false,
      default: ''
    },
    clickEvent: {
      type: Function,
      required: false,
      default: null
    }
  },
  data() {
    return {
      functionCode: 'import'
    }
  },
  methods: {
    handleClick(param) {
      if (this.clickEvent) {
        this.clickEvent(param)
      } else {
        this.import(param.file)
      }
    },
    clearFile() {
      // 上传成功之后清除历史记录,否则再次上传浏览器无响应

      this.$refs.uploader.clearFiles()
    }
  },
  inject: ['import']
}
</script>

<style scoped>
.main-report_button {
  float: left;
  margin-right: 10px;
}
</style>
